package ch.wanandroid.view;


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.widget.NestedScrollView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.BindView;
import butterknife.ButterKnife;
import ch.wanandroid.comr.wanandroid.R;

/**
 * Author: ch
 * Date: 2018/10/20 9:45
 * Description: ${DESCRIPTION}
 */

public abstract class BaseFragment extends Fragment {
    @BindView(R.id.nest_view)
    NestedScrollView mNestedScrollView;
    private boolean isBottomShow = true;
    protected int layoutId;
    BottomNavigationView mBottomNavigationView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setLayoutId();
        View view = inflater.inflate(layoutId, container, false);
        ButterKnife.bind(this, view);
        initData();
        mBottomNavigationView = getActivity().findViewById(R.id.bottom_navigation_bar);
        mNestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int
                    oldScrollX, int oldScrollY) {
                //上滑 并且 正在显示底部栏
                if (scrollY - oldScrollY > 0 && isBottomShow) {
                    isBottomShow = false;
                    //将Y属性变为底部栏高度  (相当于隐藏了)
                    mBottomNavigationView.animate().translationY(mBottomNavigationView.getHeight());
                } else if (scrollY - oldScrollY < 0 && !isBottomShow) {
                    isBottomShow = true;
                    mBottomNavigationView.animate().translationY(0);
                }
            }
        });
        return view;
    }

    protected abstract void initData();


    protected abstract void setLayoutId();
}
